@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">书管理</a>
            <em></em>
            <a href="{{route('Admin.Home.booksWordList')}}">书籍列表</a>
            <em></em>
            <a href="#">章节列表</a>
        </div>

        <div class="filter-box clearfix">

            <div class="fr">
                <a class="addBtn" href="{{route("Admin.Home.booksChapterSet")}}?books_info_id={{$booksInfoId}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>读物名称</th>
                    <th>章节名称</th>
                    @if($booksInfo && $booksInfo->type == 'audio')
                    <th>音频</th>
                    @endif
                    <th>阅读币价格</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($booksChapters) > 0)
                    @foreach($booksChapters as $booksChapter)
                        <tr id="banner_{{$booksChapter->id}}">
                            <td>{{$booksChapter->id}}</td>
                            <td>@if($booksChapter->books_Info){{$booksChapter->books_Info->name}} @endif</td>
                            <td>{{$booksChapter->name}}</td>
                            @if( $booksChapter->books_Info && $booksChapter->books_Info->type == 'audio')
                            <td class="account-td" style="width:30%;">
                                <audio controls="controls" src="{{$booksChapter->audio_url}}"></audio>
                            </td>
                            @endif
                            <td>{{$booksChapter->books_coin_price}}</td>
                            <td>
                                @if($booksChapter->status == 0)
                                    <p style="color: red">下架</p>
                                @else
                                    <p style="color: green;">上架</p>
                                @endif
                            </td>
                            <td><a class="color2" href="{{route("Admin.Home.booksChapterSet")}}?books_info_id={{$booksInfoId}}&id={{$booksChapter->id}}">编辑</a> <span>|</span> <a href="javascript:void(0);" class="del" data-id="{{$booksChapter->id}}">删除 </a></td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
        <div class="pagelist" style="text-align: center;">
            <?php echo $booksChapters->appends(['books_info_id' => $booksInfoId])->render(); ?>
        </div>
    </div>
    <script>
        $(function(){

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");
                $.ajax({
                    url:'{{route("Api.Admin.sys.delBooksChapter")}}',
                    type:'post',
                    dataType:'json',
                    data:{id:id},
                    success:function(obj){
                        if(obj.level == "success"){
                            $("#banner_"+id).hide('slow');
                        }else{
                            noty({type:obj.level,text:obj.message,timeout:600});
                        }
                    },
                    error:function(obj){
                        console.log(obj);
                    }

                });
            });
        });
    </script>
@endsection